package nsu.edu.zsq.controller.teacher;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;

import nsu.edu.zsq.bean.StuScore;
import nsu.edu.zsq.common.JsonData;
import nsu.edu.zsq.param.PageQuery;
import nsu.edu.zsq.param.StuScoreParam;
import nsu.edu.zsq.param.TchCourseParam;
import nsu.edu.zsq.service.teacher.CourseScoreService;

/** 
* Description: 教师课程成绩管理的controller<br>
*/
@RequestMapping("/teacher/score")
@Controller
public class CourseScoreController {

    @Autowired
    private CourseScoreService courseScoreService;
    
    /**
     * 获取教师教授的主修课程列表
     * @return JsonData
     */
    @RequestMapping("/listMajorTchCourse")
    @ResponseBody
    public JsonData listMajorTchCourse() {
        List<TchCourseParam> listTchCourse = courseScoreService.listMajorTchCourse();
        return JsonData.success(listTchCourse);
    }
    
    /**
     * 跳转到成绩管理页面
     * @param classId 班级id
     * @param courseNo 课程代码
     * @param tchCourseId 教师课程id
     * @param model
     * @return String teacher/scoreManager/tchCourse_student_list.html
     */
    @RequestMapping("/toStudent_list")
    public String toStudent_list(@RequestParam("classId")int classId, @RequestParam("courseNo")String courseNo,
            @RequestParam("tchCourseId")int tchCourseId, Model model) {
        model.addAttribute("classId", classId);
        model.addAttribute("courseNo", courseNo);
        model.addAttribute("tchCourseId", tchCourseId);
        return "teacher/scoreManager/tchCourse_student_list.html";
    }
    
    /**
     * 获取班级学生课程成绩列表
     * @param classId 班级id
     * @return JsonData
     */
    @RequestMapping("/listStuScore")
    @ResponseBody
    public JsonData listStuScore(@RequestParam("classId")int classId, @RequestParam("courseNo")String courseNo, PageQuery pageQuery) {
        PageInfo<StuScoreParam> listStudent = courseScoreService.listStuScoreByClassId(classId, courseNo, pageQuery);
        return JsonData.success(listStudent);
    }
    
    /**
     * 保存一条学生课程成绩信息
     * @param stuScore 学生课程成绩信息
     * @return JsonData
     */
    @RequestMapping("/saveStuScore")
    @ResponseBody
    public JsonData saveStuScore(StuScore stuScore) {
        courseScoreService.saveStuScore(stuScore);
        return JsonData.success();
    }
    
    // =================================================选修课成绩管理=============================================
    /**
     * 获取教师教授的选修课程列表
     * @return JsonData
     */
    @RequestMapping("/listMinorTchCourse")
    @ResponseBody
    public JsonData listMinorTchCourse() {
        List<TchCourseParam> listTchCourse = courseScoreService.listMinorTchCourse();
        return JsonData.success(listTchCourse);
    }
    
    /**
     * 跳转到成绩管理页面
     * @param classId 班级id
     * @param model
     * @return String teacher/scoreManager/tchCourse_minorStudent_list.html
     */
    @RequestMapping("/toMinorStudent_list")
    public String toMinorStudent_list(@RequestParam("tchCourseId")int tchCourseId, Model model) {
        model.addAttribute("tchCourseId", tchCourseId);
        return "teacher/scoreManager/tchCourse_minorStudent_list.html";
    }
    
    /**
     * 获取班级学生课程成绩列表
     * @param classId 班级id
     * @return JsonData
     */
    @RequestMapping("/listMinorStuScore")
    @ResponseBody
    public JsonData listMinorStuScore(@RequestParam("tchCourseId")int tchCourseId, PageQuery pageQuery) {
        PageInfo<StuScoreParam> listStudent = courseScoreService.listStuScoreByTchCourseId(tchCourseId, pageQuery);
        return JsonData.success(listStudent);
    }
    
    // =================================================补考成绩管理=============================================
    
    /**
     * 获取该教师所授课程下需要补考的学生成绩信息
     * @param pageQuery 分页数据
     * @return JsonData
     */
    @RequestMapping("/listResitStuScore")
    @ResponseBody
    public JsonData listResitStuScore(PageQuery pageQuery) {
        PageInfo<StuScoreParam> listResitStuScore = courseScoreService.listResitStuScore(pageQuery);
        return JsonData.success(listResitStuScore);
    }
    
    /**
     * 编辑学生补考成绩
     * @param stuScore 学生课程成绩信息
     * @return JsonData
     */
    @RequestMapping("/updateResitScore")
    @ResponseBody
    public JsonData updateResitScore(StuScore stuScore) {
        courseScoreService.updateResitScore(stuScore);
        return JsonData.success();
    }
    
    // =================================================重修成绩管理=============================================
    
    /**
     * 获取该教师所授课程下需要重修的学生成绩信息
     * @param pageQuery 分页数据
     * @return JsonData
     */
    @RequestMapping("/listRetakeStuScore")
    @ResponseBody
    public JsonData listRetakeStuScore(PageQuery pageQuery) {
        PageInfo<StuScoreParam> listResitStuScore = courseScoreService.listRetakeStuScore(pageQuery);
        return JsonData.success(listResitStuScore);
    }
    
    /**
     * 编辑学生重修成绩
     * @param stuScore 学生课程成绩信息
     * @return JsonData
     */
    @RequestMapping("/updateRetakeScore")
    @ResponseBody
    public JsonData updateRetakeScore(StuScore stuScore) {
        courseScoreService.updateRetakeScore(stuScore);
        return JsonData.success();
    }
}
